package fy.mdm.operator;

import com.seeyon.v3x.services.flow.bean.FlowExport;
import com.seeyon.v3x.services.form.bean.ValueExport;
import fy.form.listen.operate.AForm_Save_Operator;
import fy.form.listen.operate.IFormOperator;
import fy.mdm.bean.PartNewCustomerBean;
import fy.mdm.dao.FiexdAssetReviewDao;
import fy.mdm.dao.PartNewCustomerDao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

public class PartNewCustomerOperator extends AForm_Save_Operator implements
        IFormOperator {
    private static Log log = LogFactory.getLog(FiexdAssetReviewDao.class);
    private PartNewCustomerBean bean = new PartNewCustomerBean();
    @Override
    public String getFormName() {
        return "配件客户新增申请表";
    }

    @Override
    protected void parseOtherField_FirstStep(FlowExport flowExport) {
        bean.setSummaryId(super.formBean.getSummaryId());
        bean.setBillname(flowExport.getFlowTitle());
        bean.setApplier(flowExport.getFlowCreatePerson().getId());
        bean.setTs(flowExport.getFlowCreateTime());
    }
    @Override
    protected void parseValueExport(ValueExport ve) {
        System.out.println("parseValueExport PartNewCustomerOperator");
        log.info("parseValueExport PartNewCustomerOperator");
        String fieldName = ve.getDisplayName();
        log.info("fieldName="+fieldName);
        if ("客户编码".equals(fieldName)) {
            bean.setCUSTOMER_CODE(ve.getValue());
        }else if("填写日期".equals(fieldName)){
            bean.setCREATE_TIME(ve.getValue());
        }else if("客户名称".equals(fieldName)){
            bean.setCUSTOMER_NAME(ve.getValue());
        }else if("客户简称".equals(fieldName)){
            bean.setCUSTOMER_SHORT_NAME(ve.getValue());
        }else if("客户类型".equals(fieldName)){
            bean.setCUSTOMER_STYLE(ve.getValue());
        }else if("客户类别".equals(fieldName)){
            bean.setCUSTOMER_CATEGORY(ve.getValue());
        }else if("客户国别".equals(fieldName)){
            bean.setCOUNTRY(ve.getValue());
        }else if("纳税登记编号".equals(fieldName)){
            bean.setTAX_REGISTRATION_NUMBER(ve.getValue());
        }else if ("付款条件".equals(fieldName)){
            bean.setPAYMENT_CLAUSE(ve.getValue());
        }else if("信用天数".equals(fieldName)){
            bean.setDAYS(ve.getValue());
        }else if("销售片区".equals(fieldName)){
            bean.setAREA(ve.getValue());
        }else if("价目表".equals(fieldName)){
            bean.setPRICE_LIST(ve.getValue());
        }else if("法人代表".equals(fieldName)){
            bean.setLEGAL_REPRESENTATIVE(ve.getValue());
        }else if("法人电话".equals(fieldName)){
            bean.setLEGAL_REPRESENTATIVE_PHONE(ve.getValue());
        }else if("省份".equals(fieldName)){
            bean.setPROVINCE(ve.getValue());
        }else if("城市".equals(fieldName)){
            bean.setCITY(ve.getValue());
        }else if("客户注册地址".equals(fieldName)){
            bean.setADDRESS(ve.getValue());
        }else if("联系人".equals(fieldName)){
            bean.setNAME(ve.getValue());
        }else if("联系电话".equals(fieldName)){
            bean.setPHONE(ve.getValue());
        }else if("收货地址1".equals(fieldName)){
            bean.setADDRESS1(ve.getValue());
        }else if("收货地址2".equals(fieldName)){
            bean.setADDRESS2(ve.getValue());
        }else if("收货地址3".equals(fieldName)){
            bean.setADDRESS3(ve.getValue());
        }
       // String approver=getValues(ve.getSummaryid()).get("审批人");
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        bean.setAPPROVER_TIME(format);
    }
    @Override
    protected boolean save() {
        try {
            System.out.println("save PartNewCustomerOperator");
            PartNewCustomerDao partNewCustomerDao = new PartNewCustomerDao();
            partNewCustomerDao.setPartNewCustomerBean(bean);
            return partNewCustomerDao.StateReturn();

        } catch (Exception e) {
            e.printStackTrace();
        }finally {

        }
        return success;
    }


}
